package com.ldc.wandroid.viewmodel;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.ldc.common.mvvm.ViewModelBase;
import com.ldc.wandroid.model.ProjectsModel;
import com.ldc.common.net.Api2Request;
import com.ldc.wandroid.server.ApiServer;

import java.util.ArrayList;
import java.util.List;

public class ProjectTabViewModel extends ViewModelBase {
    private final ApiServer apiServer = Api2Request.getInstance().createServer(ApiServer.class);
    private final MutableLiveData<Boolean> _loading = new MutableLiveData<>(false);

    public LiveData<Boolean> getLoading() {
        return _loading;
    }

    private final MutableLiveData<List<ProjectsModel>> projects = new MutableLiveData<>();

    public LiveData<List<ProjectsModel>> getProjects() {
        return projects;
    }


    public void loadProjects() {
        _loading.setValue(true);
        apiRequest(apiServer.get_projects(), (status,result, throwable) -> {
            _loading.setValue(false);
            if (result.isSuccess()) {
                projects.setValue(result.getData());
            } else {
                projects.setValue(null);
            }
        });
    }
}
